<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>添加笔记</title>
    <link rel="stylesheet" type="text/css" href="aui-20170109-v2.1/css/aui.css"/>
</head>
<body>
    <header class="aui-bar aui-bar-nav">
        <a class="aui-pull-left aui-btn" onclick="javascript: history.back()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">添加笔记</div>
        <a class="aui-pull-right aui-btn aui-btn-outlined">
            <i id="save_icon" class="aui-iconfont aui-icon-correct" onclick="save_btn()"></i>
        </a>
    </header>
    <div class="aui-content aui-margin-b-15">
        <ul class="aui-list aui-form-list">
            <!--				<li class="aui-list-header">双击切换修改</li>-->
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">
                        标题
                    </div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="title" id="title">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">
                        账号
                    </div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="account" id="account">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">
                        密码
                    </div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="password" id="password">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">
                        常用
                    </div>
                    <div class="aui-list-item-input">
                        <input type="checkbox" class="aui-switch" id="stick">
                    </div>
                </div>
            </li>
        </ul>
    </div>
</body>
<script src="js/jquery-3.4.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="aui-20170109-v2.1/script/aui-dialog.js" type="text/javascript" charset="utf-8"></script>
<script src="aui-20170109-v2.1/script/aui-toast.js" type="text/javascript" charset="utf-8"></script>
<script src="aui-20170109-v2.1/script/api.js" type="text/javascript" charset="utf-8"></script>
<script src="js/sha3.js"></script>
<script src="js/aes.js"></script>
<script src="js/md5.js"></script>
<script src="js/cloud_sync.js"></script>
<script type="text/javascript">
    var dialog = new auiDialog();
    var toast = new auiToast();
    var noteId;
    var pwNotes;
    $(function () {
        pwNotes = localStorage.getItem("PWnotes");
        if (!pwNotes) {
            pwNotes = {
                id:1,
                list:[]
            };
            noteId = "pwnote1";
        } else {
            pwNotes = JSON.parse(pwNotes);
            pwNotes.id++;
            noteId = "pwnote" + pwNotes.id ;
        }
    })
    function save_btn() {
        var k = false;
        $("input").each(function () {
            if (k) return;
            let val = $.trim($(this).val());
            if (!val) {
                dialog.alert({
                    title:"Error!",
                    msg:"请勿留空！",
                    buttons:["关闭"]
                })
                k = true;
            }
        })
        if (!k) {
            var pwNote={
                title: $.trim($("#title").val()),
                account: $.trim($("#account").val()),
                password: $.trim($("#password").val()),
                stick:$("#stick")[0].checked
            }
            var note={
                "noteId": noteId,
                "title":$.trim($("#title").val()),
                stick:$("#stick")[0].checked
            }
            localStorage.setItem(noteId,JSON.stringify(pwNote));
            $("#stick")[0].checked ? pwNotes.list.unshift(note) : pwNotes.list.push(note);
            pwNotes.version = new Date().getTime();
            localStorage.setItem("PWnotes", JSON.stringify(pwNotes));
            // if (is_sync=="true") cloud_sync();
            toast.success({
                title: "添加成功！"
            });
            setTimeout(function () {
                location.href = 'PWnotes.html';
            }, 1000);
        }
    }
</script>
</html>